﻿using System;

namespace Web.BaseCode
{

    public class CommValue
    {
        /// <summary>
        /// 文章分类
        /// </summary>
        public static int ArticleClass
        {
            get { return 1; }
        }

        /// <summary>
        /// 文章标签
        /// </summary>
        public static int ArticleTag
        {
            get { return 2; }
        }

        /// <summary>
        /// 列表中文章截取的长度
        /// </summary>
        public static int ArticleLength
        {
            get { return Common.ConfigHelper.GetConfigInt("ArticleLength"); }
        }

        /// <summary>
        /// 列表显示的文章数量
        /// </summary>
        public static int PageSize
        {
            get { return Common.ConfigHelper.GetConfigInt("PageSize"); }
        }

        /// <summary>
        /// 主域名
        /// </summary>
        public static string Domain
        {
            get { return Common.ConfigHelper.GetConfigString("domain"); }
        }

        /// <summary>
        /// 边栏分类
        /// </summary>
        public static System.Data.DataSet SideBarClass
        {
            get
            {
                System.Data.DataSet ds = null;
                Object obj = CacheProvider.GetCache("SideBarClass");
                if (obj == null)
                {
                    BLL.BLL_Tags bll = new BLL.BLL_Tags();
                    ds = bll.GetSideBarByTagType(CommValue.ArticleClass);
                    CacheProvider.SetCache("SideBarClass", ds, DateTime.Now.AddDays(1), System.Web.Caching.Cache.NoSlidingExpiration);
                }
                else
                {
                    ds = (System.Data.DataSet)obj;
                }

                return ds;
            }
        }

        /// <summary>
        /// 边栏文章tag
        /// </summary>
        public static System.Data.DataSet SideBarTag
        {
            get
            {
                System.Data.DataSet ds = null;
                Object obj = CacheProvider.GetCache("SideBarTag");
                if (obj == null)
                {
                    BLL.BLL_Tags bll = new BLL.BLL_Tags();
                    ds = bll.GetSideBarByTagType(CommValue.ArticleTag);
                    CacheProvider.SetCache("SideBarTag", ds, DateTime.Now.AddDays(1), System.Web.Caching.Cache.NoSlidingExpiration);
                }
                else
                {
                    ds = (System.Data.DataSet)obj;
                }

                return ds;
            }
        }

        /// <summary>
        /// 边栏最新文章
        /// </summary>
        public static System.Data.DataSet SideNewArticle
        {
            get
            {

                System.Data.DataSet ds = null;
                Object obj = CacheProvider.GetCache("SideNewArticle");
                if (obj == null)
                {
                    BLL.BLL_Article bll = new BLL.BLL_Article();
                    ds = bll.GetSideBarArticles();
                    CacheProvider.SetCache("SideNewArticle", ds, DateTime.Now.AddDays(1), System.Web.Caching.Cache.NoSlidingExpiration);
                }
                else
                {
                    ds = (System.Data.DataSet)obj;
                }
                return ds;
            }
        }

        /// <summary>
        /// 首页第一页文章
        /// </summary>
        public static System.Data.DataSet HomeArticleList
        {
            get
            {
                System.Data.DataSet ds = null;
                Object obj = CacheProvider.GetCache("HomeArticleList");
                if (obj == null)
                {
                    BLL.BLL_Article bll = new BLL.BLL_Article();
                    ds = bll.GetPageList(PageSize, 1, null);
                    int count = bll.GetCount(null);

                    //更新首页的同时更新文章总数量
                    CacheProvider.SetCache("HomeArticleList", ds, DateTime.Now.AddDays(1), System.Web.Caching.Cache.NoSlidingExpiration);
                    CacheProvider.SetCache("HomeArticleListCount", count, DateTime.Now.AddDays(1), System.Web.Caching.Cache.NoSlidingExpiration);
                }
                else
                {
                    ds = (System.Data.DataSet)obj;
                }
                return ds;
            }
        }

        /// <summary>
        /// 首页文章总数量
        /// </summary>
        public static int HomeArticleListCount
        {
            get
            {
                int count = 0;
                Object obj = CacheProvider.GetCache("HomeArticleListCount");
                if (obj == null)
                {
                    BLL.BLL_Article bll = new BLL.BLL_Article();
                    System.Data.DataSet ds = bll.GetPageList(PageSize, 1, null);
                    count = bll.GetCount(null);

                    //更新总数量的同时更新首页文章
                    CacheProvider.SetCache("HomeArticleList", ds, DateTime.Now.AddDays(1), System.Web.Caching.Cache.NoSlidingExpiration);
                    CacheProvider.SetCache("HomeArticleListCount", count, DateTime.Now.AddDays(1), System.Web.Caching.Cache.NoSlidingExpiration);
                }
                else
                {
                    count = (int)obj;
                }
                return count;
            }

        }
    }

    /// <summary>
    /// 博客中的url类型
    /// </summary>
    public enum BlogPageType
    {
        /// <summary>
        /// 首页
        /// </summary>
        Home = 1,
        /// <summary>
        /// 栏目
        /// </summary>
        Item = 2,
        /// <summary>
        /// 分类
        /// </summary>
        Category = 3,
        /// <summary>
        /// 标签
        /// </summary>
        Tag = 4,
        /// <summary>
        /// 搜索
        /// </summary>
        Search = 5,
        /// <summary>
        /// 文章内容页
        /// </summary>
        Article = 6
    }
}